#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    softKeyboard = new SoftKeyboard();
    handKeyboard = new HandKeyboard();
    ui->lineEdit_1->installEventFilter(this);
    ui->lineEdit_2->installEventFilter(this);

    this->close();
//    softKeyboard->show();

}

//事件过滤器处理函数
bool Widget::eventFilter(QObject *watched, QEvent *event)
{
    if(event->type()==QEvent::MouseButtonRelease)//事件类型
    {
        QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);//将事件强制转换
        if(mouseEvent->button() == Qt::LeftButton)
        {
            if(watched == ui->lineEdit_1)
            {
                softKeyboard->textShow = ui->lineEdit_1;
                softKeyboard->show();


            }
            else if(watched == ui->lineEdit_2)
            {
                handKeyboard->show();
            }
        }
    }
    return QWidget::eventFilter(watched,event);//返回父类的事件过滤器
}

Widget::~Widget()
{
    delete ui;
}

